//
//  FLMLoginVC.m
//  FLMSuperSOS
//
//  Created by xiaoyang on 16/9/5.
//  Copyright © 2016年 GuangzhouFaLaoMiaoNetworkTechnologyCo. All rights reserved.
//

#import "FLMLoginVC.h"
#import "FLMRegisterVC.h"
#import "BaseHttpRequest.h"

#import "FLMForgetPasswordVC.h"

#import "FLMSettingViewController.h"
#import "FLMRegisterVC.h"
@interface FLMLoginVC (){
    
    UIScrollView * scr;
    UITextField * usernameText,*passwordText;
}
@end

@implementation FLMLoginVC

- (void)viewDidLoad {
    [super viewDidLoad];

    
    [self setUpNavContent];

    
    scr=[LSF_Util add_scollview:CGRectMake(0, 64, ScreenW, ScreenH-64) Tag:1 View:self.view co:CGSizeMake(0, ScreenH)];
    
    //用户名
    [LSF_Util labelName:@"账号" fontSize:14.0f rect:CGRectMake(20, 30, 40, 30) View:scr Alignment:0 Color:black Tag:1];
    usernameText=[LSF_Util addTextFieldView:CGRectMake(70, 30, ScreenW-100, 30) Tag:1 textColor:black Alignment:0 Text:nil placeholderStr:@"请输入用户名" View:scr font:14.0f];
    [usernameText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    [LSF_Util setXianTiao:ColorHUI rect:CGRectMake(70, 60, ScreenW-100, 1) view:scr];
    
    
    //密码
    [LSF_Util labelName:@"密码" fontSize:14.0f rect:CGRectMake(20, 80, 40, 30) View:scr Alignment:0 Color:black Tag:1];
    passwordText=[LSF_Util addTextFieldView:CGRectMake(70, 80, ScreenW-100, 30) Tag:1 textColor:black Alignment:0 Text:nil placeholderStr:@"请输入密码" View:scr font:14.0f];
    [passwordText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    [LSF_Util setXianTiao:ColorHUI rect:CGRectMake(70, 110, ScreenW-100, 1) view:scr];
    
    
    //忘记密码按钮
    UIButton * forgetPasswordBtn= [LSF_Util buttonPhotoAlignment:nil hilPhoto:nil rect:CGRectMake(ScreenW-100, 120, 90, 30) title:@"忘记密码?" Tag:1 View:scr textColor:gray Size:font14 backgroundColor:nil];
    [forgetPasswordBtn addTarget:self action:@selector(forgetPasswordAction) forControlEvents:UIControlEventTouchUpInside];
    
    
    //立即登录按钮
    UIButton * loginBtn= [LSF_Util buttonPhotoAlignment:@"loginWhite" hilPhoto:@"loginHightLight" rect:CGRectMake(50, 180, ScreenW-100, 35) title:nil Tag:1 View:scr textColor:orange Size:font14 backgroundColor:MS_RGBA(242, 242, 242, 0.7)];

    [loginBtn addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
    
    //超级登陆img
    [LSF_Util addSubviewImage:@"login1" rect:CGRectMake((ScreenW-347/2)/2,235, 374/2, 203/2) View:scr Tag:1];
    
    [LSF_Util labelName:@"为您得生活提供更优惠得福利,为您得生活精打细算" fontSize:13.0 rect:CGRectMake(0,235+203/2+20,ScreenW,40) View:scr Alignment:1 Color:gray Tag:1];
    
}


#pragma mark --------------------
#pragma mark 设置导航栏
- (void)setUpNavContent
{
    //设置导航栏上的左边item
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftItem) image:@"navigationButtonReturn" hightImage:@"navigationButtonReturnClick"];
    //设置导航栏上的又边item
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTitle:@"注册" target:self action:@selector(rightItem)];

}


- (void)viewWillAppear:(BOOL)animated
{
    //设置标题
    self.navigationItem.title = @"登录";
    //设置标题颜色
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor blackColor]};
}

#pragma mark --------------------
#pragma mark 左边item
- (void)leftItem
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark --------------------
#pragma mark 右边item
- (void)rightItem
{
    FLMRegisterVC *registerVc = [[FLMRegisterVC alloc] init];
    [self.navigationController pushViewController:registerVc animated:YES];
}

-(void)textFieldDidChange:(UITextField *)textField
{
    NSLog(@"输入改变的文本%@",textField.text);
    
}

//注册按钮触发
-(void)actNavRightBtn{
    
    FLMRegisterVC * registerView =[[FLMRegisterVC alloc] init];
    [self.navigationController pushViewController:registerView animated:YES];
    
}

- (void)actNavLeftBtn
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}


//忘记密码按钮触发
-(void)forgetPasswordAction{
    
    FLMForgetPasswordVC * forgetpassword =[[FLMForgetPasswordVC alloc] init];
    
    [self.navigationController pushViewController:forgetpassword animated:YES];
    
}

//立即登录按钮
-(void)loginAction{
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
    //用户名
    [params setValue:@"bhzhuo" forKey:@"uname"];
    //用户密码
    [params setValue:[BaseHttpRequest md5HexDigest:[NSString stringWithFormat:@"%@%@",@"123456",@"sos_5941m"]] forKey:@"upass"];

    //验证码
    [params setValue:@"" forKey:@"code"];
    //令牌
    [params setValue:@"f2c8ec76b30527be791752cab0cf743c" forKey:@"token"];
    
    //h
    [params setValue:@"141" forKey:@"h"];

    //辅助参数
//    [params setValue:@"" forKey:@"H"];
    
    
    NSLog(@"参数--%@",params);
    
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer = [AFHTTPResponseSerializer serializer];
    session.requestSerializer = [AFHTTPRequestSerializer serializer];
    session.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", @"text/plain", nil];
    

    
    //http://192.168.1.101/Users/login
    [session POST:LoginURL parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"----成功%@",[[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding]);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
         NSLog(@"----失败%@",error);
        
    }];
    
//    [BaseHttpRequest loginWithURL:@"http://192.168.1.101/Api/Users/login" parameters:params success:^(__autoreleasing id *dicData) {
//        
//    
//        
//    } fail:^(NSError *error) {
//        
//        NSLog(@"----失败%@",error);
//        
//    }];
    
}


@end
